import '@common/css/reset.scss';
import './components/header/index.ts';
import './components/title/index.ts';
import './components/footer/index.ts';
import './components/main/index.ts';
import './components/aside/index.ts';
import './components/upload/index.ts';
import './index.scss';


declare const layui: any;
declare const $: any;

layui.use(['layer', 'form'], function () {
  const layer = layui.layer,
    form = layui.form;
  const inputs = []
  $("button[type=submit]").on("click", function () {
    const forms = $(this).closest("form");
    const page = $(forms.context).attr("html");
    $.ajax({
      url: forms[0].action,
      type: forms[0].method,
      data: forms.serialize(),
      dataType: "json",
      success(res: any) {
        if (res.data == 1) {
          if (page == "show") {
            show(res.data)
          } else {
            window.location.href = ""
          }
        } else {
          layer.msg(res.info, { icon: 2 })
        }
      }, error() {
        layer.msg("提交失败")
        if (page == "show") {
          show("")
        } else {
          window.location.href = ""
        }
      }
    })
    return false;
  })
  function show(link: string) {
    $(".tk").addClass("show");
  }
  $(".btns").on("click", ".cancel", function () {
    $(".tk").removeClass("show");
  })
})
